package com.example.image.option

import com.bumptech.glide.load.engine.DiskCacheStrategy

class ImageOptions private constructor(
    val placeImage :Int,
    val errorImage :Int,
    val skipMemoryCache :Boolean,
    val diskCacheStrategy : DiskCacheStrategy,
    val isCircle:Boolean,
    val roundRadius :Int,
    val isGif:Boolean,
    val isStaticImg :Boolean,
    val imgSize:IntArray

) {


    /**
     * 提供Builder来接收参数
     * */
    companion object Builder{
        private var placeImage = 0
        private var errorImage = 0
        private var skipMemoryCache = false
        private var diskCacheStrategy = DiskCacheStrategy.NONE
        private var isCircle = false
        private var roundRadius = 0
        private var isGif = true
        private var isStaticImg = false
        private var imgSize = intArrayOf()

        //提供Set方法来改变值
        fun setPlaceImage(placeImage: Int): Builder {
            Builder.placeImage = placeImage
            return this
        }

        fun setErrorImage(errorImage: Int): Builder {
            Builder.errorImage = errorImage
            return this
        }

        fun isStaticImage(isStaticImg: Boolean): Builder {
            Builder.isStaticImg = isStaticImg
            return this
        }

        fun isGifImage(isGif: Boolean): Builder {
            Builder.isGif = isGif
            return this
        }

        fun setImageSize(imgSize: IntArray): Builder {
            Builder.imgSize = imgSize
            return this
        }

        fun skipMemoryCache(skipMemoryCache: Boolean): Builder {
            Builder.skipMemoryCache = skipMemoryCache
            return this
        }

        fun setDiskCacheStrategy(diskCacheStrategy: DiskCacheStrategy): Builder {
            Builder.diskCacheStrategy = diskCacheStrategy
            return this
        }

        fun setCircleImage(isCircle: Boolean = true): Builder {
            Builder.isCircle = isCircle
            return this
        }
        fun setCommonImage(isCircle: Boolean=true) : Builder{
            this.isCircle= !isCircle
            return this
        }

        fun setRoundRadius(radius: Int): Builder {
            roundRadius = radius
            return this
        }


        /**
         * 对外提供一个build方法 来创建对象
         * */

        fun build(): ImageOptions {
            return ImageOptions(placeImage, errorImage, skipMemoryCache, diskCacheStrategy, isCircle, roundRadius, isGif, isStaticImg, imgSize)
        }


    }
}